package top.lenjon.lib.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.lenjon.lib.entity.UserDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * <p>
 * 用户信息 Mapper 接口
 * </p>
 *
 * @author wei
 * @since 2020-11-09
 */
@Repository
public interface UserDetailMapper extends BaseMapper<UserDetail> {

    /**
     * 根据用户名返回密码hash
     *
     * @param username username
     * @return pwd hash
     */
    @Select("SELECT password FROM user_detail WHERE username =#{username} AND enabled = 1 LIMIT 0,1")
    String getPasswordByUsername(String username);

    @Select("SELECT count(id) FROM user_detail WHERE username=#{username} LIMIT 0,1")
    Integer getCountByUsername(String username);

    @Select("SELECT * FROM user_detail WHERE username=#{username} LIMIT 0,1")
    UserDetail getIdByUserName(String username);

    @Update("UPDATE user_detail SET enabled=true WHERE id=#{id}")
    void setEnabledById(int id);

    @Select("SELECT * FROM user_detail WHERE enabled = 1")
    List<UserDetail> getAll();
}
